﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.Review;
using Newtonsoft.Json;
using WMS_MAV;

namespace MVC_System.Controllers
{
    public class ReviewController : Controller
    {
        private readonly IConfiguration _configuration;

        public ReviewController(IConfiguration configuration)
        {
            _configuration = configuration; 
        }
        /// <summary>
        /// 复检显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ReviewList()
        {
            return View();
        }
        /// <summary>
        ///复检显示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> ReviewsShow(ReviewDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "Workshop/api/Reviews/Get?pageIndex=" + dto.pageIndex + "&pageSize=" + dto.pageSize + "&reviewNo=" + dto.reviewNo + "&reviewName=" + dto.reviewName + "&reviewState=" + dto.reviewState;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 复检删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> ReviewsDelete(ReviewDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "Workshop/api/Reviews/Deletes";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        /// <summary>
        /// 复检反填
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> ReviewsFinds(ReviewModelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "Workshop/api/Reviews/GetById?ReviewId=" + dto.reviewId;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 复检状态修改 
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> ReviewsState(ReviewModelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "Workshop/api/Reviews/EquipmentStateUpdate?ReviewId=" + dto.reviewId;
            //string url = _configuration["Url"] + "Review/api/Reviews/ReviewStateUpdate?ReviewId=" + dto.reviewId;13151317982
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        ///复检查看
        /// </summary>
        /// <returns></returns>
        public IActionResult ReviewsFind()
        {
            return View();
        }
    }
}
